import request from '@/util/request'
import md5 from 'js-md5'

export function secondaryRegister(headers, data) {
  data.userPassword = md5(data.userPassword)
  return request({
    url: '/aqs/secondary/regist.json',
    method: 'post',
    data,
    headers,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}

export function listSecondary(index, size, params) {
  return request({
    url: `/aqs/secondary/list/${index}/${size}.json`,
    method: 'get',
    params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}

export function getUserRelate(id) {
  return request({
    url: `/aqs/secondary/getUserRelate/${id}.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
// 修改备注
export function updateRemark(params) {
  return request({
    url: '/aqs/secondary/updateRemark.json',
    method: 'put',
    data: params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
// 修改权限
export function updatePermission(params) {
  return request({
    url: '/aqs/secondary/updatePermission.json',
    method: 'put',
    data: params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
// 重新申请
export function grantSecondaryAccount(params) {
  return request({
    url: '/aqs/secondary/grantSecondaryAccount.json',
    method: 'post',
    data: params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
// 子账号删除
export function removeUserRelate(id) {
  return request({
    url: `/aqs/secondary/${id}.json`,
    method: 'delete',
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
// 解除关系
export function cancelRelationship(data) {
  return request({
    url: '/aqs/secondary/cancelRelationship.json',
    method: 'put',
    data: data,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}

// 重新申请
export function againGrandSA(params) {
  return request({
    url: '/aqs/secondary/againGrandSA.json',
    method: 'put',
    data: params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}

// 恢复关系
export function recoverRelationship(params) {
  return request({
    url: '/aqs/secondary/recoverRelationship.json',
    method: 'put',
    data: params,
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}
